package com.example.administrator.daggerdemo.base2.base;

import com.example.administrator.daggerdemo.model.network.response.SimpleResponseInfo;


import rx.Observer;

/**
 * Created by zhengjian on 2016/12/12.
 */
public abstract class BaseObserver<T extends SimpleResponseInfo> implements Observer<T> {

    public abstract void onFail(String failMsg);
    public abstract void onFail(int failId);
    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {
        onFail("网络错误");
    }

    @Override
    public void onNext(T t) {
          if(t.getResult()==1)
          {
              onSuccess(t);
          }else
          {

                 //显示公用错误码
                switch (t.getResult())
                {
                    case 2:
                        onFail("error2");
                        break;
                    default:
                        onFail(t.getResult());
                        break;

                }
          }
    }

    public abstract void onSuccess(T bean);
}
